import { createStore, applyMiddleware } from 'redux'
import { combineReducers } from 'immutable'
import thunk from 'redux-thunk'
import { composeWithDevTools } from 'redux-devtools-extension'

let moduleFn = require.context('./reducers', false, /\.js$/)
let modules = moduleFn.keys().reduce((p, c) => {
  let value = moduleFn(c).default
  let key = c.match(/\.\/(\w+)\.js$/)[1]
  p[key] = value
  return p
}, {})

// 合并为一大的reducer
let reducer = combineReducers(modules)

export default createStore(reducer, composeWithDevTools(applyMiddleware(thunk)))
